package cn.wolfcode.luowowo.scenic.service.impl;

import cn.wolfcode.luowowo.api.cache.domain.ScenicRankStatisVO;
import cn.wolfcode.luowowo.api.cache.prefix.ScenicPrefix;
import cn.wolfcode.luowowo.api.cache.service.IRedisService;
import cn.wolfcode.luowowo.api.cache.service.IScenicStatisRedisService;
import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.scenic.domain.Scenic;
import cn.wolfcode.luowowo.scenic.domain.ScenicTheme;
import cn.wolfcode.luowowo.scenic.mapper.ScenicMapper;
import cn.wolfcode.luowowo.scenic.query.ScenicQueryObject;
import cn.wolfcode.luowowo.scenic.service.IScenicService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScenicServiceImpl implements IScenicService{

    @Autowired
    private ScenicMapper scenicMapper;

    @Reference
    private IScenicStatisRedisService scenicStatisRedisService;

    public Scenic queryById(Long id) {
        return scenicMapper.selectByPrimaryKey(id);
    }

    public List<Scenic> getAll() {
        return scenicMapper.selectAll();
    }

    public List<Scenic> getTop5(Long id) {
        List<ScenicRankStatisVO> vos = scenicStatisRedisService.getTopNum(ScenicPrefix.SCENIC_TOP5_PREFIX, id, 4);
        ArrayList<Scenic> top = new ArrayList<>();
        for (ScenicRankStatisVO vo : vos) {
            Scenic scenic = scenicMapper.selectByPrimaryKey(vo.getScenicId());
            top.add(scenic);
        }
        return top;
    }

    public List<Scenic> getHotCommed(Long id) {
        List<ScenicRankStatisVO> vos = scenicStatisRedisService.getTopNum(ScenicPrefix.SCENIC_HOTCOMMEND_PREFIX, id, 8);
        ArrayList<Scenic> top = new ArrayList<>();
        for (ScenicRankStatisVO vo : vos) {
            Scenic scenic = scenicMapper.selectByPrimaryKey(vo.getScenicId());
            top.add(scenic);
        }
        return top;
    }

    public PageInfo queryByTheme(ScenicQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Scenic> list = scenicMapper.selectByTheme(qo);
        return new PageInfo(list);
    }
}
